#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define vec vector<int>
#define fi first
#define se second
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int M = 321;
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;

int id[N],siz[N],ans[M][N],a[N],f[N],lim,lasans,n,tot,m;
vec v[N];

void build(int x,int ID = 0){
	id[x] = ID ? ID : ++tot; int t = id[x];
	memset(ans[t],0x3f,sizeof(ans[t]));
	for(int i = 1,j = inf;i <= n;i++)
		if(a[i] == x) j = 0;
		else ans[t][a[i]] = min(ans[t][a[i]],++j);
	for(int i = n,j = inf;i;i--)
		if(a[i] == x) j = 0;
		else ans[t][a[i]] = min(ans[t][a[i]],++j);
	ans[t][x] = 0; vec zero; v[x].swap(zero);
}

void merge(int x,int y){
	vec res; int i = 0,j = 0;
	while(i < v[x].size() && j < v[y].size()) res.pb(v[x][i] < v[y][j] ? v[x][i++] : v[y][j++]);
	while(i < v[x].size()) res.pb(v[x][i++]);
	while(j < v[y].size()) res.pb(v[y][j++]);
	v[y] = res;
}

int merge_q(int x,int y){
	int res = inf,i = 0,j = 0; if(!v[x].size() || !v[y].size()) return inf;
	while(i < v[x].size() && j < v[y].size()) res = min(res,v[x][i] < v[y][j] ? v[y][j] - v[x][i++] : v[x][i] - v[y][j++]);
	while(i < v[x].size()) res = min(res,abs(v[x][i++]-v[y].back()));
	while(j < v[y].size()) res = min(res,abs(v[y][j++]-v[x].back()));
	return res;
}

int query(int x,int y){
	x = f[x],y = f[y]; if(siz[x] > siz[y]) swap(x,y);
	if(!siz[x] || !siz[y]) return -1; if(x == y) return 0;
	if(siz[y] <= lim) return merge_q(x,y);
	else if(siz[x] <= lim) return min(ans[id[y]][x],merge_q(x,y));
	else return min(ans[id[y]][x],min(ans[id[x]][y],merge_q(x,y)));
}

void change(int x,int y){
	int blx = f[x] , bly = f[y];
	if(!siz[blx] || blx == bly) return;
	if(siz[blx] > siz[bly]) f[y] = blx,f[x] = n+1,swap(blx,bly);
	else f[x] = n+1;
	if(blx > n || bly > n) return;
	x = blx,y = bly;
	if(siz[y] <= lim){
		if(siz[x] + siz[y] <= lim){
			for(int i : v[x]) a[i] = y; for(int i = 1;i <= tot;i++) ans[i][y] = min(ans[i][y],ans[i][x]); merge(x,y);
		}else {for(int i : v[x]) a[i] = y; build(y);}
	}else if(siz[x] <= lim){
		if(siz[x] + v[y].size() <= lim){
			for(int i : v[x]) a[i] = y; for(int i = 1;i <= tot;i++) ans[i][y] = min(ans[i][y],ans[i][x]); merge(x,y);
		}else {for(int i : v[x]) a[i] = y; build(y,id[y]);}
	}else{for(int i = 1;i <= n;i++) if(a[i] == x) a[i] = y; build(y,id[y]);}
	siz[y] += siz[x]; siz[x] = 0; vec zero; v[x].swap(zero);
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in; lim = sqrt(n); for(int i = 1;i <= n;i++) siz[a[i] = in]++,v[a[i]].pb(i),f[i] = i;
	for(int i = 0;i <= n;i++) if(siz[i] > lim) build(i);
	while(m--){
		int op = in,x = in ^ lasans,y = in ^ lasans;
		if(op == 1) change(x,y);
		else{lasans = query(x,y); if(~lasans) printf("%d\n",lasans); else lasans = 0,puts("Ikaros");}
	}
	return 0;
}
